﻿using Glue;
using Glue.Internals;
using GlueTests.Builders;
using Xunit;

namespace GlueTests.ConverterContainerTests
{
    public class When_not_AcceptNullablesAsNormalTypes
    {
        private readonly ConverterContainer converters;
        private readonly IObjectMember booleanProperty;
        private readonly IObjectMember nullableBooleanProperty;

        public When_not_AcceptNullablesAsNormalTypes()
        {
            converters = new ConverterContainer();
            converters.AcceptNullablesAsNormalTypes = false;
            nullableBooleanProperty = PropertyBuilder.AsNullableBooleanProperty().Build();
            booleanProperty = PropertyBuilder.AsBooleanProperty().Build();
        }

        [Fact]
        public void Should_not_AcceptNullablesAsNormalTypes()
        {
            Assert.False(converters.CanConvert(nullableBooleanProperty, booleanProperty));
            Assert.False(converters.CanConvert(booleanProperty, nullableBooleanProperty));
        }

        [Fact]
        public void Should_not_return_converter_for_AcceptNullablesAsNormalTypes()
        {

            Assert.Throws(typeof(GlueException), () => converters.Get(nullableBooleanProperty, booleanProperty, RelationDirection.TwoWays));
            Assert.Throws(typeof(GlueException), () => converters.Get(booleanProperty, nullableBooleanProperty, RelationDirection.TwoWays));
        }
    }
}
